package lab9.com.acme.bankapp.service.bank;

import lab9.com.acme.bankapp.domain.bank.Account;
import lab9.com.acme.bankapp.domain.bank.Bank;
import lab9.com.acme.bankapp.domain.bank.CheckingAccount;
import lab9.com.acme.bankapp.domain.bank.Client;
import lab9.com.acme.bankapp.domain.bank.Gender;
import lab9.com.acme.bankapp.domain.bank.SavingAccount;


public class BankApplication
{
	
	public static final String BAL = "\tBalance: ";
	public static final String ID = "ID: ";
	public static final String CL = "Client #";
	private static final String M_B_MY = "\nModified bank:\tmyBank";
	private static final String B_MY = "Bank:\tmyBank";

	public static void main(String[] args)
	{
		Bank myBank = new Bank(10);
		for (int i = 0; i < 10; i++)
		{
			Client newClient;
			if (i % 2 == 0)
			{
				newClient = new Client(Integer.toString(i), Gender.MALE, 1);
				newClient.addAccount(new SavingAccount(100 + i * 10));		
			}
			else
			{
				newClient = new Client(Integer.toString(i), Gender.FEMALE, 1);
				newClient.addAccount(new CheckingAccount(100 + i * 10, 100));
			}
			myBank.addClient(newClient);
		}		
		System.out.println(B_MY);
		printBalance(myBank);
		System.out.println(M_B_MY);
		modifyBank(myBank);
		printBalance(myBank);
	}
	
	
	private static void modifyBank(Bank curBank)
	{
		Client[] curClients = curBank.getClients();
		Account[] curClientAccounts = curClients[0].getAccounts();
		curClientAccounts[0].deposit(15);
		curClientAccounts = curClients[4].getAccounts();
		curClientAccounts[0].withdraw(60);
		curClientAccounts = curClients[7].getAccounts();
		curClientAccounts[0].withdraw(180);
	}
	

	public static void printBalance(Bank curBank)
	{
		Client[] curClients = curBank.getClients();
		for (int i = 0; i < curBank.getNumberOfClients(); i++)
		{
			System.out.println(CL + i);
			curClients[i].getClientSalutation();
			Account[] curClientAccounts = curClients[i].getAccounts();
			for (int j = 0; j < curClients[i].getNumberOfAccounts(); j++)
			{
				System.out.println(ID + curClientAccounts[0].getID() + 
						BAL + curClientAccounts[0].getBalance());
			}
		}
	}
	
}
